package com.xbongbong.saas.service.impl;/*/*/

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.model.PaasCommentModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.message.pojo.dto.ConsistencySyncRabbitMqDTO;
import com.xbongbong.pro.message.pojo.vo.ConsistencySyncRabbitMqVO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.feign.ConsistencySyncWorkOrderFeignClient;
import com.xbongbong.saas.model.BomProductModel;
import com.xbongbong.saas.model.CommunicatePlanUserModel;
import com.xbongbong.saas.model.DingBundleModel;
import com.xbongbong.saas.model.DingBundleRankModel;
import com.xbongbong.saas.model.DingBundleUserModel;
import com.xbongbong.saas.model.DingReportModel;
import com.xbongbong.saas.model.InstockProductModel;
import com.xbongbong.saas.model.LikeModel;
import com.xbongbong.saas.model.OpportunityProductModel;
import com.xbongbong.saas.model.OutstockProductModel;
import com.xbongbong.saas.model.ProductStockModel;
import com.xbongbong.saas.model.ProductionOrderProductModel;
import com.xbongbong.saas.model.SignInModel;
import com.xbongbong.saas.model.SupplierProductModel;
import com.xbongbong.saas.model.WorkReportCcModel;
import com.xbongbong.saas.service.AssembleService;
import com.xbongbong.saas.service.BatchFlowBillService;
import com.xbongbong.saas.service.ClueService;
import com.xbongbong.saas.service.ClueUserService;
import com.xbongbong.saas.service.CommunicatePlanService;
import com.xbongbong.saas.service.ConsistencySyncService;
import com.xbongbong.saas.service.ContactService;
import com.xbongbong.saas.service.ContractProductService;
import com.xbongbong.saas.service.ContractService;
import com.xbongbong.saas.service.ContractUserService;
import com.xbongbong.saas.service.CreditCardBillService;
import com.xbongbong.saas.service.CreditFixedLimitService;
import com.xbongbong.saas.service.CreditLimitService;
import com.xbongbong.saas.service.CreditTemporaryLimitService;
import com.xbongbong.saas.service.CustomerCommunicateService;
import com.xbongbong.saas.service.CustomerService;
import com.xbongbong.saas.service.CustomerStatementService;
import com.xbongbong.saas.service.CustomerUserService;
import com.xbongbong.saas.service.InstockService;
import com.xbongbong.saas.service.InventoryService;
import com.xbongbong.saas.service.InvoiceService;
import com.xbongbong.saas.service.OpportunityService;
import com.xbongbong.saas.service.OpportunityUserService;
import com.xbongbong.saas.service.OutstockService;
import com.xbongbong.saas.service.PayBalanceService;
import com.xbongbong.saas.service.PayPlanService;
import com.xbongbong.saas.service.PayPlanSheetService;
import com.xbongbong.saas.service.PaymentService;
import com.xbongbong.saas.service.PaymentSheetService;
import com.xbongbong.saas.service.PaymentUserService;
import com.xbongbong.saas.service.ProductSerialService;
import com.xbongbong.saas.service.ProductService;
import com.xbongbong.saas.service.ProductWarehouseService;
import com.xbongbong.saas.service.ProductionOrderService;
import com.xbongbong.saas.service.PurchaseInvoiceService;
import com.xbongbong.saas.service.PurchaseService;
import com.xbongbong.saas.service.QuotationProductService;
import com.xbongbong.saas.service.QuotationService;
import com.xbongbong.saas.service.QuotationUserService;
import com.xbongbong.saas.service.RefundService;
import com.xbongbong.saas.service.ReturnedPurchaseService;
import com.xbongbong.saas.service.SupplierCommunicateService;
import com.xbongbong.saas.service.SupplierContactService;
import com.xbongbong.saas.service.TransferService;
import com.xbongbong.saas.service.WorkOrderService;
import com.xbongbong.workorder.service.WorkOrderFlowUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 数据一致性同步 实现
 * @author 魏荣杰
 * @date 2019/6/11 11:24
 * @since v1.0
 * @version v1.0
 */
@Service("consistencySyncService")
public class ConsistencySyncServiceImpl implements ConsistencySyncService {
    private static final Logger LOG = LoggerFactory
            .getLogger(ConsistencySyncServiceImpl.class);

    @Resource
    private CommunicatePlanService communicatePlanService;
    @Resource
    private ContractService contractService;
    @Resource
    private ContactService contactService;
    @Resource
    private OpportunityService opportunityService;
    @Resource
    private PaymentService paymentService;
    @Resource
    @Lazy
    private CustomerCommunicateService customerCommunicateService;
    @Resource
    private InvoiceService invoiceService;
    @Resource
    private WorkOrderService workOrderService;
    @Resource
    private SignInModel signInModel;
    @Resource
    private OpportunityProductModel opportunityProductModel;
    @Resource
    private ContractProductService contractProductService;
    @Resource
    private PaasCommentModel paasCommentModel;
    @Resource
    private CommunicatePlanUserModel communicatePlanUserModel;
    @Resource
    private ContractUserService contractUserService;
    @Resource
    private CustomerUserService customerUserService;
    @Resource
    private LikeModel likeModel;
    @Resource
    private OpportunityUserService opportunityUserService;
    @Resource
    private PaymentUserService paymentUserService;
    @Resource
    private WorkReportCcModel workReportCcModel;
    @Resource
    private PayPlanService payPlanService;
    @Resource
    private PurchaseService purchaseService;
    @Resource
    private SupplierContactService supplierContactService;
    @Resource
    private SupplierCommunicateService supplierCommunicateService;
    @Resource
    private WorkOrderFlowUserService workOrderFlowUserService;
    @Resource
    private AssembleService assembleService;
    @Resource
    private InventoryService inventoryService;
    @Resource
    private TransferService transferService;
    @Resource
    private ProductionOrderService productionOrderService;
    @Resource
    private InstockService instockService;
    @Resource
    private OutstockService outstockService;
    @Resource
    private ProductStockModel productStockModel;
    @Resource
    private ProductWarehouseService productWarehouseService;
    @Resource
    private ProductionOrderProductModel productionOrderProductModel;
    @Resource
    private QuotationProductService quotationProductService;
    @Resource
    private QuotationUserService quotationUserService;
    @Resource
    private QuotationService quotationService;
    @Resource
    private BomProductModel bomProductModel;
    @Resource
    private RefundService refundService;
    @Resource
    private SupplierProductModel supplierProductModel;
    @Resource
    private PaymentSheetService paymentSheetService;
    @Resource
    private PurchaseInvoiceService purchaseInvoiceService;
    @Resource
    private PayPlanSheetService payPlanSheetService;
    @Resource
    private PayBalanceService payBalanceService;
    @Resource
    private CustomerStatementService customerStatementService;
    @Resource
    private CustomerStatementStatisticServiceImpl customerStatementStatisticService;
    @Resource
    private CustomerService customerService;
    @Resource
    private ProductService productService;
    @Resource
    private ReturnedPurchaseService returnedPurchaseService;
    @Resource
    private BatchFlowBillService batchFlowBillService;
    @Resource
    private ProductSerialService productSerialService;
    @Resource
    private ClueUserService clueUserService;
    @Resource
    private DingBundleModel dingBundleModel;
    @Resource
    private DingBundleUserModel dingBundleUserModel;
    @Resource
    private DingBundleRankModel dingBundleRankModel;
    @Resource
    private DingReportModel dingReportModel;
    @Resource
    private ClueService clueService;
    @Resource
    private OutstockProductModel outstockProductModel;
    @Resource
    private InstockProductModel instockProductModel;
    @Resource
    private CreditLimitService creditLimitService;
    @Resource
    private CreditTemporaryLimitService creditTemporaryLimitService;
    @Resource
    private CreditFixedLimitService creditFixedLimitService;
    @Resource
    private CreditCardBillService creditCardBillService;
    @Resource
    private ConsistencySyncWorkOrderFeignClient consistencySyncWorkOrderFeignClient;

    @Override
    public ConsistencySyncRabbitMqVO syncCustomer(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String name = consistencySyncRabbitMqDTO.getName();
            //同步访客计划表
            communicatePlanService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //同步联系人列表
            contactService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //同步合同列表
            contractService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //同步销售机会列表
            opportunityService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //同步应收款列表
            paymentService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //跟进记录客户名称
            customerCommunicateService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //合同合作客户
            contractService.dataConsistencyUpdatePartner(corpid, dataId, name);
            //同步发票列表关联客户名称
            invoiceService.dataConsistencyUpdate(corpid, dataId, name, InvoiceEnum.CUSTOMER_NAME.getAttr(), InvoiceEnum.CUSTOMER_NAME_LINK_TEXT.getAttr());
            //工单同步
            workOrderService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //签到同步
            signInModel.dataConsistencyUpdateCustomer(corpid, dataId, name);
            // 同步报价单列表
            quotationService.dataConsistencyUpdate(corpid, dataId, name, QuotationEnum.CUSTOMER_ID.getAttr(), QuotationEnum.CUSTOMER_NAME.getAttr());
            //同步回款单列表关联客户名称
            paymentSheetService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            //同步客户对账单关联客户名称
            customerStatementService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            // 同步退货退款
            refundService.dataConsistencyUpdate(corpid, dataId, name, RefundEnum.CUSTOMER_ID.getAttr(), RefundEnum.CUSTOMER_ID_LINKED_TEXT.getAttr());
            // 同步销售出库单
            outstockService.dataConsistemcyUpdateCustomerName(corpid, dataId, name);
            // 同步上级客户
            customerService.dataConsistencyUpdateParentCustomer(corpid, dataId, name);
            // 同步对账单中的客户名称
            customerStatementStatisticService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            // 同步信用额度、临时额度、固定额度、信用流水中的经销商名称
            creditLimitService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            creditTemporaryLimitService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            creditFixedLimitService.dataConsistencyUpdateCustomer(corpid, dataId, name);
            creditCardBillService.dataConsistencyUpdateCustomer(corpid, dataId, name);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncContact(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String name = consistencySyncRabbitMqDTO.getName();
            //同步合同列表
            contractService.dataConsistencyUpdateContact(corpid, dataId, name);
            //同步机会列表-联系人
            opportunityService.dataConsistencyUpdateContact(corpid, dataId, name);
            // 同步报价单列表-联系人
            quotationService.dataConsistencyUpdate(corpid, dataId, name, QuotationEnum.CONTACT_ID.getAttr(), QuotationEnum.CONTACT_NAME.getAttr());
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncContract(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String name = consistencySyncRabbitMqDTO.getName();
            String serialNo = consistencySyncRabbitMqDTO.getSerialNo();
            //同步发票列表关联合同名称
            invoiceService.dataConsistencyUpdateContract(corpid, dataId, serialNo);
            // 同步应收款表
            paymentService.dataConsistencyUpdateContract(corpid, dataId, name);
            // 同步跟进记录表
            customerCommunicateService.dataConsistencyUpdateLinkBusiness(corpid, dataId, serialNo, XbbRefTypeEnum.CONTRACT.getCode());
            // 同步退货退款
            refundService.dataConsistencyUpdate(corpid, dataId, serialNo, RefundEnum.CONTRACT_ID.getAttr(), RefundEnum.CONTRACT_ID_LINKED_TEXT.getAttr());
            //同步回款单列表关联合同编号
            paymentSheetService.dataConsistencyUpdateContract(corpid, dataId, serialNo);
            // 同步客户对账单表列表关联合同编号
            customerStatementService.dataConsistencyUpdateContract(corpid, dataId, name);
            // 同步销售出库单关联的合同编号
            outstockService.dataConsistencyUpdateContract(corpid, dataId, serialNo);
            // 同步工单关联的合同编号
            workOrderService.dataConsistencyUpdateContract(corpid, dataId, serialNo);
            // 同步工单关联的合同编号
            consistencySyncWorkOrderFeignClient.syncContract(consistencySyncRabbitMqDTO);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncOpportunity(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String serialNo = consistencySyncRabbitMqDTO.getSerialNo();
            //同步跟进记录表
            customerCommunicateService.dataConsistencyUpdateLinkBusiness(corpid, dataId, serialNo, XbbRefTypeEnum.SALES_OPPORTUNITY.getCode());
            // 同步报价单列表-合同
            quotationService.dataConsistencyUpdate(corpid, dataId, serialNo, QuotationEnum.OPPORTUNITY_ID.getAttr(), QuotationEnum.OPPORTUNITY_NAME.getAttr());
            // 同步合同关联的销售机会字段
            contractService.dataConsistencyUpdateOpportunity(corpid, dataId, serialNo, ContractEnum.LINK_OPPORTUNITY_HIDE.getAttr());
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncProduct(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String name = consistencySyncRabbitMqDTO.getName();
            String specification = consistencySyncRabbitMqDTO.getSpecification();
            String serialNo = consistencySyncRabbitMqDTO.getSerialNo();
            //同步刷新机会产品表
            opportunityProductModel.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            //同步刷新合同产品表
            contractProductService.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            //同步刷新生产单产品表
            productionOrderProductModel.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            //同步刷新报价单产品表
            quotationProductService.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            //同步bom单产品信息
            bomProductModel.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            // 同步出库产品表
            outstockProductModel.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
            // 同步入库产品表
            instockProductModel.dataConsistencyUpdate(corpid, dataId, name, specification, serialNo);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncUser(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            LOG.info("ConsistencySyncServiceImpl.syncUser start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            String name = consistencySyncRabbitMqDTO.getName();
            String avatar = consistencySyncRabbitMqDTO.getAvatar();
            String userId = consistencySyncRabbitMqDTO.getUserId();
            //评论员工姓名和头像
    		paasCommentModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//评论被回复对象员工姓名
            paasCommentModel.dataConsistencyUpdateRefUser(corpid, userId, name);
    		//访客计划执行者姓名和头像
    		communicatePlanUserModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//合同销售团队姓名和头像
    		contractUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//客户销售团队姓名和头像
    		customerUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//点赞姓名和头像
    		likeModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//销售机会销售团队姓名和头像
    		opportunityUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//回款员工姓名和头像
    		paymentUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    		//工作报告抄送名字同步
			workReportCcModel.dataConsistencyUpdateUser(corpid, userId, name);
			//签到名字同步
            signInModel.dataConsistencyUpdateUser(corpid, userId, name);
            //工单团队姓名和头像
            workOrderFlowUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            //报价单团队姓名和头像
            quotationUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            // 线索团队姓名和头像
            clueUserService.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            //服务群的群名称和群头像
            dingBundleModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            //群成员的名称和头像
            dingBundleUserModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            //喜报列表中成员的名称和头像
            dingReportModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            //业绩排行中成员的名称和头像
            dingBundleRankModel.dataConsistencyUpdateUser(corpid, userId, name, avatar);
            LOG.info("ConsistencySyncServiceImpl.syncUser end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncSupplier(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            LOG.info("ConsistencySyncServiceImpl.syncSupplier start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            String name = consistencySyncRabbitMqDTO.getName();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            // 付款计划
            payPlanService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            // 采购合同
            purchaseService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //进项发票
            purchaseInvoiceService.dataConsistencyUpdateSupplier(corpid,dataId,name);
            // 供应商联系人
            supplierContactService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            // 供应商跟进记录
            supplierCommunicateService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步产品详情页供应商名称
            productService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步付款单列表关联供应商名称
            payPlanSheetService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步预付款列表关联供应商名称
            payBalanceService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步采购退货单的供应商名称
            returnedPurchaseService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步采购入库单的供应商名称
            instockService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            //同步采购退货出库单的供应商名称
            outstockService.dataConsistencyUpdateSupplier(corpid, dataId, name);
            LOG.info("ConsistencySyncServiceImpl.syncSupplier end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            // 供应商产品
            supplierProductModel.dataConsistencyUpdateSupplier(corpid, dataId, name);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncWarehouse(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            LOG.info("ConsistencySyncServiceImpl.syncWarehouse start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            String name = consistencySyncRabbitMqDTO.getName();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            //装配出入库 出入仓库
            assembleService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //盘点单
            inventoryService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //调拨单 调出入仓库
            transferService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //生产单 出入仓库
            productionOrderService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //入库单 入库仓库
            instockService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //出库单 出库仓库
            outstockService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //批次库存
            productStockModel.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            //分仓
            productWarehouseService.dataConsistencyUpdateWarehouse(corpid, dataId, name);
            LOG.info("ConsistencySyncServiceImpl.syncWarehouse end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncQuotation(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            LOG.info("ConsistencySyncServiceImpl.syncQuotation start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String serialNo = consistencySyncRabbitMqDTO.getSerialNo();
            // 合同 关联报价单(合同关联报价单显示的是报价单的编号)
            contractService.dataConsistencyUpdateQuotation(corpid, dataId, serialNo);
            // 同步跟进记录表-关联报价
            customerCommunicateService.dataConsistencyUpdateLinkBusiness(corpid, dataId, serialNo, XbbRefTypeEnum.QUOTATION.getCode());
            LOG.info("ConsistencySyncServiceImpl.syncQuotation end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncPurchase(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try {
            LOG.info("ConsistencySyncServiceImpl.syncPurchase start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String serialNo = consistencySyncRabbitMqDTO.getName();
            instockService.dataConsistencyUpdateSeriNo(corpid, dataId, serialNo);
            //同步付款单列表关联采购编号
            payPlanSheetService.dataConsistencyUpdatePurchase(corpid, dataId, serialNo);
            //同步进项发票列表关联采购合同编号
            purchaseInvoiceService.dataConsistencyUpdatePurchase(corpid,dataId,serialNo);
            LOG.info("ConsistencySyncServiceImpl.syncPurchase end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncPayment(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException{
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            LOG.info("ConsistencySyncServiceImpl.syncPayment start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String serialNo = consistencySyncRabbitMqDTO.getName();
            invoiceService.dataConsistencyUpdatePayment(corpid,dataId,serialNo);
            LOG.info("ConsistencySyncServiceImpl.syncPurchase end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqVO));
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncPayPlan(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException{
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            LOG.info("ConsistencySyncServiceImpl.syncPayPlan start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String serialNo = consistencySyncRabbitMqDTO.getName();
            purchaseInvoiceService.dataConsistencyUpdatePayPlan(corpid,dataId,serialNo);
            LOG.info("ConsistencySyncServiceImpl.syncPayPlan end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqVO));
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncBatchFlowBill(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            LOG.info("ConsistencySyncServiceImpl.syncBatchFlowBill start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            Integer visible = consistencySyncRabbitMqDTO.getVisible();
            batchFlowBillService.dataConsistencyUpdateBatchFlowBill(corpid, dataId, visible);
            LOG.info("ConsistencySyncServiceImpl.syncBatchFlowBill end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqVO));
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncMarketActivity(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            clueService.dataConsistencyUpdateMarketActivity(consistencySyncRabbitMqDTO.getCorpid(), consistencySyncRabbitMqDTO.getDataId(), consistencySyncRabbitMqDTO.getName());
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncClue(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String companyName = consistencySyncRabbitMqDTO.getName();
            customerService.dataConsistencyUpdateClue(corpid, dataId, companyName);
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncSeqSearch(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            LOG.info("ConsistencySyncServiceImpl.syncSeqSearch start, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            Integer visible = consistencySyncRabbitMqDTO.getVisible();
            productSerialService.dataConsistencyUpdateSeqSearch(corpid, dataId, visible);
            LOG.info("ConsistencySyncServiceImpl.syncSeqSearch end, consistencySyncRabbitMqDTO = " + JSON.toJSONString(consistencySyncRabbitMqVO));
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

    @Override
    public ConsistencySyncRabbitMqVO syncCompetitor(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String companyName = consistencySyncRabbitMqDTO.getName();
            opportunityService.dataConsistencyUpdateCompetitor(corpid, dataId, companyName);
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }


    @Override
    public ConsistencySyncRabbitMqVO syncInvoice(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException {
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String invoiceSerialNo = consistencySyncRabbitMqDTO.getName();
            paymentService.dataConsistencyUpdateInvoice(corpid, dataId, invoiceSerialNo);
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }


    @Override
    public ConsistencySyncRabbitMqVO syncContractOutStock(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) throws XbbException{
        ConsistencySyncRabbitMqVO consistencySyncRabbitMqVO = new ConsistencySyncRabbitMqVO();
        try{
            String corpid = consistencySyncRabbitMqDTO.getCorpid();
            Long dataId = consistencySyncRabbitMqDTO.getDataId();
            String contractOutStockSerialNo = consistencySyncRabbitMqDTO.getName();
            paymentService.dataConsistencyUpdateContractOutStock(corpid, dataId, contractOutStockSerialNo);
        }catch (XbbException e){
            throw e;
        }catch (Exception e){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return consistencySyncRabbitMqVO;
    }

}
